• Hello PublishPress Future team,
    A critical error related to manual workflow triggers occurred in the previous version.
    I am reporting this because updating the plugin to the latest version did not resolve the issue.

    Error message:

    Warning: Attempt to read property "ID" on null in
    /wp-content/plugins/post-expirator/src/Modules/Workflows/Models/PostModel.php on line 124
    
    Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, false given in
    /wp-content/plugins/post-expirator/src/Modules/Workflows/Models/PostModel.php:125

    The issue appears to occur inside:

    public function getManuallyEnabledWorkflows(): array
    {
        $selectedWorkflowIds = get_post_meta(
            $this->post->ID,
            self::META_KEY_WORKFLOW_MANUALLY_TRIGGERED,
            false
        );
    
        $selectedWorkflowIds = array_map('intval', $selectedWorkflowIds);
    
        return $selectedWorkflowIds;
    }

    The following is a report of improvements made in ChatGPT.

    The issue appears to occur inside:

    It seems $this->post can become null under some conditions, possibly due to:

    • orphaned postmeta records
    • deleted posts
    • deleted workflows
    • inconsistent workflow metadata after plugin updates
    • REST API preload during block editor initialization

    In this case, the plugin attempts to access:

    $this->post->ID

    without validating that $this->post is a valid WP_Post object.

    Additionally, get_post_meta() may return a non-array value, which later causes:

    array_map(): Argument #2 ($array) must be of type array, false given

    Suggested fix:

    public function getManuallyEnabledWorkflows(): array
    {
        if (!$this->post || !isset($this->post->ID)) {
            return [];
        }
    
        $selectedWorkflowIds = get_post_meta(
            $this->post->ID,
            self::META_KEY_WORKFLOW_MANUALLY_TRIGGERED,
            false
        );
    
        if (!is_array($selectedWorkflowIds)) {
            return [];
        }
    
        return array_map('intval', $selectedWorkflowIds);
    }

    I believe adding these guards would prevent fatal crashes caused by inconsistent metadata or deleted content.

    This concludes the answers obtained through ChatGPT.

    Thank you for your work on the plugin.

Viewing 1 replies (of 1 total)
  • Plugin Support Riza Prihananto

    (@rizaprihananto)

    Hi @piyoko ,

    Thank you for addressing your concern regarding this.
    Let me share this to our developer for the insight. Your feedback means a lot to us.

    If you have another concern, feel free to reply to this message.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.