Title: PHP Warning Message
Last modified: May 19, 2026

---

# PHP Warning Message

 *  Resolved [mystercp](https://wordpress.org/support/users/mystercp/)
 * (@mystercp)
 * [2 weeks, 5 days ago](https://wordpress.org/support/topic/php-warning-message-14/)
 * Hi guys,
   I’m seeing a repeating warning being logged in my hosting portal. I 
   pasted the error message into Claude and uploaded the plugin zip. It came up 
   with a reasoning and solution for the error.I asked Claude to write a post that
   I can copy/paste for you detailing the issue:**PHP Warning: Attempt to read property“
   post_type” on null — display.php line 312**
 * Version: 4.2.4
 * Seeing the following in error logs:
 *     ```wp-block-code
       PHP Warning: Attempt to read property "post_type" on null in /widget-options/includes/widgets/display.php on line 312
       ```
   
 * The issue is in the `is_single()` branch (~line 307). When the global `$post`
   is empty, the code calls `get_post()` as a fallback but doesn’t null-check the
   result before accessing `->post_type`:
 *     ```wp-block-code
       if (!$post) {
           $current_post = get_post();
           $type = $current_post->post_type; // Warning if get_post() returns null
       }
       ```
   
 * `get_post()` can return null in certain contexts (REST API requests, some AJAX
   calls) where `is_single()` is true but no post object is available.
 * Suggested fix:
 *     ```wp-block-code
       if (!$post) {
           $current_post = get_post();
           $type = $current_post ? $current_post->post_type : '';
       }
       ```
   
 * Not a critical issue in terms of security, but it can cause widgets configured
   to show on specific post types to be incorrectly hidden when `get_post()` returns
   null. Also generates log noise and will surface as an error if `display_errors`
   is on.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Mej de Castro](https://wordpress.org/support/users/mej/)
 * (@mej)
 * [2 weeks, 5 days ago](https://wordpress.org/support/topic/php-warning-message-14/#post-18912319)
 * Hi [@mystercp](https://wordpress.org/support/users/mystercp/),
 * Thanks for reaching out to our support threads.
 * After relaying this to our dev team, we can confirm that the Claude AI fix recommendation
   is valid. Thank you for sharing this with us, and we’ll make sure to include 
   this fix in the next version release.
 * If there’s anything else you need, please feel free to let us know.
 * Kind Regards,
   Mej, Widget Options Team

Viewing 1 replies (of 1 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fphp-warning-message-14%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/widget-options/assets/icon-256x256.gif?rev=2513739)
 * [Widget Options – Advanced Conditional Visibility for Gutenberg Blocks & Classic Widgets](https://wordpress.org/plugins/widget-options/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/widget-options/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/widget-options/)
 * [Active Topics](https://wordpress.org/support/plugin/widget-options/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/widget-options/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/widget-options/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Mej de Castro](https://wordpress.org/support/users/mej/)
 * Last activity: [2 weeks, 5 days ago](https://wordpress.org/support/topic/php-warning-message-14/#post-18912319)
 * Status: resolved