• Resolved Imagealordiel

    (@alordiel)


    Hello,
    Our server is on PHP8.3. When a new comment from not logged in user is submitted we get a fatal error. The comment itself is recorded, but a fatal error is thrown and users end up with white screen with error message. The error trace is as follow:

    PHP Fatal error: Uncaught TypeError: Breeze_PurgeCache::purge_post_on_new_comment(): Argument #2 ($approved) must be of type int, string given, called in /public_html/wp-includes/class-wp-hook.php on line 324 and defined in /public_html/wp-content/plugins/breeze/inc/cache/purge-cache.php:420
    Stack trace: 0 /public_html/wp-includes/class-wp-hook.php(324): Breeze_PurgeCache->purge_post_on_new_comment() 1 /public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 2 /public_html/wp-includes/plugin.php(517): WP_Hook->do_action() 3 /public_html/wp-includes/comment.php(2348): do_action() 4 /public_html/wp-includes/comment.php(3700): wp_new_comment() 5 /public_html/wp-comments-post.php(25): wp_handle_comment_submission() 6 {main}
    thrown in /public_html/wp-content/plugins/breeze/inc/cache/purge-cache.php on line 420


    In purge_post_on_new_comment you have declared $approved as int while it could be int|string . Because if you check the action comment_post from wp-includes/comment.php you will see the the comment_approved can be either 1, 0, or ‘spam’ or ‘trash’

    /**
    * Fires immediately after a comment is inserted into the database.
    *
    *
    @since 1.2.0
    *
    @since 4.5.0 The $commentdata parameter was added.
    *
    *
    @param int $comment_id The comment ID.
    *
    @param int|string $comment_approved 1 if the comment is approved, 0 if not, ‘spam’ if spam.
    *
    @param array $commentdata Comment data.
    */
    do_action( ‘comment_post’, $comment_id, $commentdata[‘comment_approved’], $commentdata );

    I guess to fix this and keep the support for older PHP versions you will need to remove the typing for the $approved parameter.

    Regards,
    al

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Fatal error on submitting new comment on PHP8.3’ is closed to new replies.