Skip to:
Content

bbPress.org

Changeset 7140


Ignore:
Timestamp:
11/03/2020 09:39:14 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 branches/2.6, for 2.6.6. See #3409.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/replies/functions.php

    r7123 r7140  
    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
     
    421426
    422427                // Update the pre_trashed_reply post meta
    423                 update_post_meta( $topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies );
     428                update_post_meta( $topic_id, '_bbp_pre_trashed_replies', array_filter( $pre_trashed_replies ) );
    424429            }
    425430
     
    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.