• Resolved mystercp

    (@mystercp)


    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:

    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:

    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:

    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

    (@mej)

    Hi @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 to reply to this topic.