bbPress::register_post_statuses()

Register the post statuses used by Forums

Description

We do some manipulation of the ‘trash’ status so trashed topics and replies can be viewed from within the theme.

Source

File: bp-forums/classes/class-bbpress.php

    public static function register_post_statuses() {

        // Closed @todo clean up translation
        register_post_status(
            bbp_get_closed_status_id(),
            apply_filters( 'bbp_register_closed_post_status', array(
                'label'             => __( 'Closed', 'buddyboss' ),
                'label_count'       => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'buddyboss' ),
                'public'            => true,
                'show_in_admin_all' => true
            ) )
        );

        // Spam @todo clean up translation
        register_post_status(
            bbp_get_spam_status_id(),
            apply_filters( 'bbp_register_spam_post_status', array(
                'label'                     => __( 'Spam', 'buddyboss' ),
                'label_count'               => _n_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'buddyboss' ),
                'protected'                 => true,
                'exclude_from_search'       => true,
                'show_in_admin_status_list' => true,
                'show_in_admin_all_list'    => false
            ) )
         );

        // Orphan
        register_post_status(
            bbp_get_orphan_status_id(),
            apply_filters( 'bbp_register_orphan_post_status', array(
                'label'                     => __( 'Orphan', 'buddyboss' ),
                'label_count'               => _n_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'buddyboss' ),
                'protected'                 => true,
                'exclude_from_search'       => true,
                'show_in_admin_status_list' => true,
                'show_in_admin_all_list'    => false
            ) )
        );

        // Hidden
        register_post_status(
            bbp_get_hidden_status_id(),
            apply_filters( 'bbp_register_hidden_post_status', array(
                'label'                     => __( 'Hidden', 'buddyboss' ),
                'label_count'               => _n_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'buddyboss' ),
                'private'                   => true,
                'exclude_from_search'       => true,
                'show_in_admin_status_list' => true,
                'show_in_admin_all_list'    => true
            ) )
        );

        /**
         * Trash fix
         *
         * We need to remove the internal arg and change that to
         * protected so that the users with 'view_trash' cap can view
         * single trashed topics/replies in the front-end as wp_query
         * doesn't allow any hack for the trashed topics to be viewed.
         */
        global $wp_post_statuses;

        if ( !empty( $wp_post_statuses['trash'] ) ) {

            // User can view trash so set internal to false
            if ( current_user_can( 'view_trash' ) ) {
                $wp_post_statuses['trash']->internal  = false;
                $wp_post_statuses['trash']->protected = true;

            // User cannot view trash so set internal to true
            } else {
                $wp_post_statuses['trash']->internal = true;
            }
        }
    }

Changelog

Changelog
Version Description
bbPress (r2727) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.