Skip to:
Content

bbPress.org

Changeset 7142


Ignore:
Timestamp:
11/03/2020 09:44:00 PM (4 years ago)
Author:
johnjamesjacoby
Message:

Replies: prevent adding empty values to pre-spam & pre-trash meta data.

This commit filters empty values from meta data before saving them, as well as removing a simple type-cast and replacing it with a more intentional is_array() check. This new approach works because get_post_meta() will call maybe_unserialize() and always return an array if it exists, or return an empty string if it does not. If it's not an array, we know it should be an empty one.

In trunk, for 2.7. Fixes #3409.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r7122 r7142  
    415415
    416416                // Get pre_trashed_replies for topic
    417                 $pre_trashed_replies = (array) get_post_meta( $topic_id, '_bbp_pre_trashed_replies', true );
     417                $pre_trashed_meta = get_post_meta( $topic_id, '_bbp_pre_trashed_replies', true );
     418
     419                // Format the meta value
     420                $pre_trashed_replies = is_array( $pre_trashed_meta )
     421                    ? array_filter( $pre_trashed_meta )
     422                    : array();
    418423
    419424                // Add this reply to the end of the existing replies
     
    434439
    435440                // Get pre_spammed_replies for topic
    436                 $pre_spammed_replies = (array) get_post_meta( $topic_id, '_bbp_pre_spammed_replies', true );
     441                $pre_trashed_meta = get_post_meta( $topic_id, '_bbp_pre_spammed_replies', true );
     442
     443                // Format the meta value
     444                $pre_spammed_replies = is_array( $pre_trashed_meta )
     445                    ? array_filter( $pre_trashed_meta )
     446                    : array();
    437447
    438448                // Add this reply to the end of the existing replies
Note: See TracChangeset for help on using the changeset viewer.