Skip to:
Content

bbPress.org


Ignore:
Timestamp:
02/17/2022 08:08:28 PM (3 years ago)
Author:
johnjamesjacoby
Message:

Moderation: use the correct post_status when untrashing a topic/reply.

This change fixes a bug/regression (since WordPress 5.6.0) that was causing untrashed topics & replies to use an unintended post_status value.

It fixes it by adding a new function ('bbp_fix_untrash_post_status()') and hooking it to the wp_untrash_post_status filter in WordPress, and overriding the results as needed.

Props r-a-y.

In trunk for 2.7.0. Fixes #3433.

File:
1 edited

Legend:

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

    r7152 r7235  
    186186
    187187    return $data;
     188}
     189
     190/**
     191 * Use the previous status when restoring a topic or reply.
     192 *
     193 * Fixes an issue since WordPress 5.6.0. See
     194 * {@link https://bbpress.trac.wordpress.org/ticket/3433}.
     195 *
     196 * @since 2.6.10 bbPress (r7233)
     197 *
     198 * @param string $new_status      New status to use when untrashing. Default: 'draft'
     199 * @param int    $post_id         Post ID
     200 * @param string $previous_status Previous post status from '_wp_trash_meta_status' meta key. Default: 'pending'
     201 */
     202function bbp_fix_untrash_post_status( $new_status = 'draft', $post_id = 0, $previous_status = 'pending' ) {
     203
     204    // Bail if not Topic or Reply
     205    if ( ! bbp_is_topic( $post_id ) && ! bbp_is_reply( $post_id ) ) {
     206        return $new_status;
     207    }
     208
     209    // Prefer the previous status, falling back to the new status
     210    $retval = ! empty( $previous_status )
     211        ? $previous_status
     212        : $new_status;
     213
     214    return $retval;
    188215}
    189216
Note: See TracChangeset for help on using the changeset viewer.