Server 500 error when updating post using block editor

Based on the error logs and the behavior you’ve described, the issue with the WordPress post not updating properly and causing a 500 internal server error seems to be related to a function in your theme or a plugin that is interacting with the content, particularly images. Here’s a breakdown of what the logs suggest and some steps you can take to resolve the issue:

Error Source: The error trace points to a function forqy_image_content_attributes_callback() in your theme’s image.php file. This function is likely modifying image attributes and is being called by a regular expression match (preg_replace_callback()).

Interaction with Other Plugins: It seems that this function is being triggered during a filter application in the wordpress-seo plugin (specifically Yoast SEO’s Indexable Link Builder). The error occurs when the post is being saved and the SEO plugin tries to process the content.

Problematic Content: Since the issue is isolated to a specific post, it’s possible that there’s something unique in this post’s content (like a specific image or HTML structure) that’s causing the function to fail.

Steps to Resolve:
Check the Specific Post’s Content: Look for any unusual HTML or image attributes in the post. You mentioned custom HTML blocks; ensure that they are correctly formatted.

Debug the Theme Function: Examine the forqy_image_content_attributes_callback() function in your theme. You might need to temporarily comment out parts of this function to see if it resolves the issue. This will help isolate the problem within that function.

Theme and Plugin Conflict Check: Temporarily switch to a default WordPress theme (like Twenty Twenty-One) and try updating the post. If it works, the issue is likely within your current theme. Also, temporarily disable plugins, especially Yoast SEO, to see if there’s a conflict.

Check for Updates: Ensure that your theme, WordPress core, and all plugins are up to date. Sometimes these issues are resolved in updates.

Consult Theme/Plugin Support: If the problem persists, reach out to the support teams for your theme and the Yoast SEO plugin. They might be aware of this issue and could offer a specific solution.

Custom Fix: If you’re comfortable with PHP, you might modify the forqy_image_content_attributes_callback() function to handle whatever edge case is causing the issue. Remember to back up the original file before making changes.

Server Error Logs: Check your server error logs for any additional information that might not be visible in the WordPress debug or console output.

Restore from Backup: If you have a recent backup from before the issue started occurring, consider restoring that version of the post and then carefully reapplying any changes.

Remember, when debugging, it’s always good to have a staging environment so that your live site is not affected.

Try replacing the function with this one:

function forqy_image_placeholder( ?int $width = 4, ?int $height = 3 ) {
    try {
        // Validate width and height
        if ($width <= 0 || $height <= 0) {
            throw new InvalidArgumentException('Width and Height must be positive integers.');
        }

        // Generate SVG
        $svg = '<svg width="' . $width . '" height="' . $height . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' . $width . ' ' . $height . '"></svg>';

        // Encode SVG for use in URL
        $svg_encoded = rawurlencode($svg);

        // Construct the data URL
        $data_url="data:image/svg+xml," . $svg_encoded;

        // Return the escaped URL
        return esc_attr($data_url);
    } catch (Exception $e) {
        // Log the error
        error_log('Error in forqy_image_placeholder: ' . $e->getMessage());

        // Optionally, return a default placeholder or false
        return false;
    }
}

tech