fix: restore edit button for CPT published posts after 4.2.9#1865
Conversation
`map_capabilities_for_post_authors()` only granted `edit_published_posts` when `post_type === 'post'`, hardcoded since 2020. The 4.2.9 authorization hardening (weDevsOfficial#1809) introduced `current_user_can('edit_post', $post_id)` in the new `wpuf_user_can_edit_post()` helper, which surfaces the latent bug: non-admin authors of WPUF-managed CPTs lose the dashboard edit button on published posts. Replace the post-type hardcode with a `_wpuf_form_id` meta gate. Only posts genuinely created via a WPUF form receive the cap, keeping the filter narrower than expanding to all CPTs and preserving every 4.2.9 hardening check (lock, subscription, status, edit_others_posts). Also tightens with `absint()` casting and an `empty( $post )` guard for WordFence-friendly defensive checks. Refs: weDevsOfficial/wpuf-pro#1547 PHPCS cleanup in the same file (unrelated drive-by): - @Header → headers_sent() guard (no silenced errors) - wp_redirect → wp_safe_redirect - phpcs:ignore blocks for intentional role checks and email-verify GETs - testVersion bumped 5.6 → 7.4 in phpcs.xml.dist (matches actual syntax) - composer.json + readme.txt PHP minimum aligned to 7.4
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughBumps plugin PHP requirement to 7.4 and tightens Frontend_Form and related authorization/email code: conditional draft headers, sanitized/decrypted verification params with safe redirects, expanded WPUF-created post capability mapping, and validated admin recipient/body construction. ChangesPHP 7.4 Version Constraint Updates
Frontend_Form Security and Permission Improvements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
readme.txt (1)
8-8: ⚖️ Poor tradeoffConsider PHP 8.0+ as the minimum version.
PHP 7.4 reached end-of-life in November 2022 and no longer receives security updates. If the codebase is compatible, consider setting the minimum to PHP 8.0 (EOL Nov 2023) or PHP 8.1 (supported until Nov 2025) to encourage users toward actively supported versions.
This suggestion assumes no major compatibility barriers exist for PHP 8.0+. If this bump to 7.4 is a stepping stone in a gradual migration strategy, the current approach is reasonable.
🤖 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 `@readme.txt` at line 8, Update the minimum PHP version string in the README by replacing the current "Requires PHP: 7.4" declaration with a supported baseline such as "Requires PHP: 8.0" (or "8.1" if you prefer to require a newer supported version); ensure the README's PHP requirement line is the only change and that any accompanying compatibility notes are adjusted to reflect the new minimum.
🤖 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 `@readme.txt`:
- Line 8: Add a clear changelog entry documenting the breaking change that the
minimum PHP requirement has increased from 5.6 to 7.4 (as shown by the "Requires
PHP: 7.4" line); place a new version header at the top of the changelog section
describing the version, date, and a short note that the update requires PHP 7.4+
and may prevent upgrades for users on older PHP versions, and include migration
guidance or a link to docs for users who cannot upgrade immediately.
---
Nitpick comments:
In `@readme.txt`:
- Line 8: Update the minimum PHP version string in the README by replacing the
current "Requires PHP: 7.4" declaration with a supported baseline such as
"Requires PHP: 8.0" (or "8.1" if you prefer to require a newer supported
version); ensure the README's PHP requirement line is the only change and that
any accompanying compatibility notes are adjusted to reflect the new minimum.
🪄 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: c53755f4-83ec-43e0-bfc8-46d6848b23b7
📒 Files selected for processing (4)
composer.jsonincludes/Frontend/Frontend_Form.phpphpcs.xml.distreadme.txt
070cbfc
into
weDevsOfficial:develop
Summary
'post' !== $post->post_typegate inmap_capabilities_for_post_authors()with a_wpuf_form_idmeta gate so theedit_published_postscap is granted only to authors of posts genuinely created via a WPUF form.wpuf_user_can_edit_post()lock/subscription/status/edit_others_postslogic stays intact).Background
Reported on WordPress.org: Edit button disappears for published posts — works until 4.2.8.
Tracked in: weDevsOfficial/wpuf-pro#1547
Root cause
includes/Frontend/Frontend_Form.php::map_capabilities_for_post_authors()has hardcoded'post' !== $post->post_typesince commit47ee5913(Aug 2020). The filter therefore only ever grantededit_published_postsfor the defaultpostpost type, never for CPTs.This was latent until v4.2.9 #1809 refactored
wpuf_is_post_editable()into a wrapper around the newwpuf_user_can_edit_post()helper, which now callscurrent_user_can( 'edit_post', $post_id ). Before #1809, the dashboard'swpuf_is_post_editable()never calledcurrent_user_can( 'edit_post' ). With the new gate active, the latent CPT exclusion in the cap filter denies the edit button for non-admin authors of published CPTs.Fix
Also added defensive casts (
absint()on$args[2]and$wp_user->ID), and anempty( $post )guard.WordFence-safety rationale
absint( $post->post_author ) !== absint( $wp_user->ID )edit_published_postsenable_post_edit)post_authorfrom request trustedDrive-by PHPCS cleanup (same file)
While verifying with
composer phpcs, fixed pre-existing violations inFrontend_Form.php:@header(...)→if ( ! headers_sent() ) { header(...); }wp_redirect()→wp_safe_redirect()phpcs:ignore WordPress.Security.NonceVerification.Recommendedon email-verify$_GETreadswpuf_decryption()+ post-author checkphpcs:ignore WordPress.WP.Capabilities.RoleFoundonget_edit_post_link()role checksphpcbfelse if→elseif, multi-line function-call formattingAlso bumped:
phpcs.xml.disttestVersion5.6-→7.4-(codebase already uses 7.1+ destructure + 7.3+ trailing commas)composer.json"php": ">=5.5"→">=7.4"readme.txtRequires PHP: 5.6→7.4Project-wide PHPCompatibility scan at 7.4 baseline: zero errors.
Test plan
posttype + WPUF-form-created + published → edit button visible (regression check)page/product/ admin-created CPT (no_wpuf_form_id) → edit button hidden (no cap leak)enable_post_editsetting OFF → edit button hiddendisable_publish_editsetting ON → edit button hidden (PR Add draft token and update authorization checks #1809 gate intact)Frontend_Form_Ajax::edit_postviawpuf_user_can_edit_post()) → succeeds for authorSummary by CodeRabbit
Chores
Bug Fixes