PHP 8.2 Compatibility Issue – Null pointer in Content.php line 792
-
Hello AAM Team, I’m experiencing a PHP warning with the latest version of AAM (7.0.11) on PHP 8.2:
Error Message: Warning: Attempt to read property “post_status” on null in /wp-content/plugins/advanced-access-manager/application/Service/Content.php on line 792
Environment: – AAM Version: 7.0.11 (updated 6 days ago) – PHP Version: 8.2.x (recommended by hosting provider Infomaniak) – WordPress: [6.9]
Root Cause: In the
_map_edit_post_caps()method (line 792),get_post($post_id)returns null in some cases, but the code attempts to access$post->post_statuswithout checking if$postis a valid object first.Current Code:
php private function _map_edit_post_caps($caps, $post_id) { $post = get_post($post_id); $is_draft = $post->post_status === 'auto-draft'; // ← Fails when $post is null // ... }Suggested Fix:
php private function _map_edit_post_caps($caps, $post_id) { $post = get_post($post_id); if (!$post || !is_object($post)) { return $caps; } $is_draft = $post->post_status === 'auto-draft'; // ... rest of the code }PHP 8.2 is stricter about null safety than previous versions, so this type of check is now necessary. Could you please include this fix in the next update? Thank you for your excellent plugin!
Best regards
You must be logged in to reply to this topic.